import matplotlib.pyplot as plt
import numpy as np
def test1():
    #defin a x,y plot
    x=np.linspace(-3,3,50)
    y1 = 2*x +1
    y2 = x**2
    plt.figure()
    # set x axis limited
    plt.xlim((-1,2))
    plt.ylim((-2,3))
    # set x,y axis label
    plt.xlabel("i am x")
    plt.ylabel('i am y')

    # plt.show()
    # reset x,y axis coordinate
    new_ticks = np.linspace(-1,2,5)
    print(new_ticks)
    plt.xticks(new_ticks)
    plt.yticks([-2,-1.8,-1,1.22,3],[r'$really\ bad$', r'$bad$', r'$normal$', r'$good$', r'$really\ good$'])

    l1,= plt.plot(x,y2,label='up')
    # draw two lines in one picture and change one of them's style and line width and line color
    l2,= plt.plot(x, y1,color='red', linewidth=1.0, linestyle='--',label='down')
    plt.legend(handles=[l1,l2,],labels=['aaa','bbb'],loc='best')
    gca = 'get current axis'
    ax = plt.gca()
    ax.spines['right'].set_color('none')
    ax.spines['top'].set_color('none')
    ax.xaxis.set_ticks_position('bottom')
    ax.yaxis.set_ticks_position('left')
    # set x or y axis cross point
    ax.spines['bottom'].set_position(('data', -1))
    ax.spines['left'].set_position(('data',0))
    plt.show()
def test2():
    x = np.linspace(-3,3,50)
    y = 2*x+1


    plt.figure(num=1, figsize=(8,5))
    plt.plot(x,y)
    ax = plt.gca()
    ax.spines['top'].set_color('none')
    ax.spines['right'].set_color('none')
    ax.xaxis.set_ticks_position('bottom')
    ax.yaxis.set_ticks_position('left')
    ax.spines['left'].set_position(('data',0))
    ax.spines['bottom'].set_position(('data',0))
    x0 = 1
    y0 = 2*x0 + 1
    #  draw a point (x0,y0)

    plt.scatter(x0, y0, s=50,color='b')
    # draw a line which is (x0,y0) to (x0,0)
    plt.plot([x0,x0],[y0,0],'k--',lw=2.5)
    plt.annotate(r'$2x+1=%s$'% y0,xy=(x0,y0),xycoords='data',xytext=(+30,+0),
                 textcoords='offset points',fontsize=16,arrowprops=dict(arrowstyle='->',
                                                                        connectionstyle='arc3,rad=.2'))
    # plt.text(-3, 7,3 ,r'$This\ is\ the\ some\ text,\ mu\ \sigma_i\ \alpha_t$',
    # fontdict={'size':16,'color':'r'})
    plt.show()

def test3():
    x = np.linspace(-3, 3, 50)
    y = 0.1 * x

    plt.figure()
    # 在 plt 2.0.2 或更高的版本中, 设置 zorder 给 plot 在 z 轴方向排序
    plt.plot(x, y, linewidth=10, zorder=1)
    plt.ylim(-2, 2)
    ax = plt.gca()
    ax.spines['right'].set_color('none')
    ax.spines['top'].set_color('none')
    ax.spines['top'].set_color('none')
    ax.xaxis.set_ticks_position('bottom')
    ax.spines['bottom'].set_position(('data', 0))
    ax.yaxis.set_ticks_position('left')
    ax.spines['left'].set_position(('data', 0))
    for lable in ax.get_xticklabels() + ax.get_yticklabels():
        lable.set_fontsize(12)
        lable.set_bbox(dict(facecolor='white',edgecolor='None',alpha=0.7))
    plt.show()
def test_Scatter():
    n = 1024
    x = np.random.normal(0,1,n)
    y = np.random.normal(0,1,n)
    T = np.arctan2(y,x) # for color avlue

    plt.scatter(x,y,s=75,c=T,alpha=0.5)
    plt.xlim(-1.5,1.5)
    plt.ylim(-1.5,1.5)
    plt.show()

def test_Bar():

test_Scatter()
